Skip to content

feat(#588): per-route request body size limits - #627

Merged
Abdulazeem-code merged 1 commit into
Abdulazeem-code:mainfrom
ogaziedaniel80-droid:feature/body-size-limits-588
Aug 29, 2026
Merged

feat(#588): per-route request body size limits#627
Abdulazeem-code merged 1 commit into
Abdulazeem-code:mainfrom
ogaziedaniel80-droid:feature/body-size-limits-588

Conversation

@ogaziedaniel80-droid

Copy link
Copy Markdown
Contributor

Summary

Closes #588 — Applies per-route request body size limits instead of the previous uniform express.json({ limit: '10kb' }).

A new bodySizeLimit dispatcher middleware (src/middleware/bodyLimit.js) chooses an express.json cap based on the request path:

Endpoint type Limit
Auth (/auth/*) and /register 1kb (tighter, to blunt abuse)
Bulk /payments and /webhooks 100kb (legitimate large payloads)
All other routes 10kb (standard)

In server.js the previous duplicate global parsers were replaced with a single app.use(bodySizeLimit). The old code applied express.json() (no limit) followed by express.json({ limit: '10kb' }); the second was a no-op because the body was already parsed, so the effective cap was ~100kb everywhere — this fixes that bug too.

The 413 handler (errorHandler.js) now reports the actual cap for the offending endpoint (e.g. "Payload too large. Maximum allowed size for this endpoint is 1kb.").

Implementation note

The pinned raw-body@2.5.3 does not support limit-as-a-function, so the dispatcher forwards to three pre-built numeric-limit parsers keyed by path. This is independent of mount point, so /api/v1, /api, and / all get the correct tier.

Test plan

  • Added tests/middleware/bodyLimit.test.js — 8 tests covering: auth 1kb reject/accept, bulk 100kb accept/reject, standard 10kb reject/accept, and non-JSON bodies left unparsed.
  • Full suite: 679 passed / 37 suites.

Acceptance criteria

  • Per-route body size limits configured
  • Bulk endpoints accept up to 100kb
  • Auth endpoints restricted to 1kb
  • 413 returned for oversized payloads

Suggested review areas

server.js, src/middleware/bodyLimit.js, src/routes/v1/paymentRoutes.js, src/routes/v1/webhookRoutes.js

Apply endpoint-type specific body caps via a bodySizeLimit dispatcher:
auth/register 1kb, bulk /payments & /webhooks 100kb, standard 10kb.
Replaces the buggy duplicate global express.json parsers; oversized
payloads now return 413 with a message naming the endpoint cap.
@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

@ogaziedaniel80-droid is attempting to deploy a commit to the Abdulazeem's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

@ogaziedaniel80-droid Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Abdulazeem-code
Abdulazeem-code merged commit 472edf4 into Abdulazeem-code:main Aug 29, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add request body size limits per endpoint type

2 participants